package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	UserName string `gorm:"type:varchar(20);not null;comment:'用户名'"`
	Password string `gorm:"type:char(32);not null;comment:'用户密码'"`
}
type Goods struct {
	gorm.Model
	UserId      int64   `gorm:"type:varchar(20);not null;comment:'用户名'"`
	GoodsTitle  string  `gorm:"type:varchar(20);not null;comment:'商品名称'"`
	GoodsNum    int     `gorm:"type:int;not null;comment:'商品数量'"`
	GoodsPrice  float64 `gorm:"type:decimal(10,2);not null;comment:'商品价格'"`
	GoodsStatue string  `gorm:"type:varchar(20);not null;comment:'商品选中状态'"`
}

func (u *User) Create() error {
	return DB.Create(&u).Error
}
func (u *User) FindInfoUserName(userName string) error {
	return DB.Where("user_name", userName).Limit(1).Find(&u).Error
}

// TODO 添加
func (g *Goods) Create() error {
	return DB.Create(&g).Error
}

// TODO 查询
func (g *Goods) FindGoodsId(goodsId int64) error {
	return DB.Where("goods_id", goodsId).Limit(1).Find(&g).Error
}

// TODO 详情
func (g *Goods) FindInfoGoodsName(goodsTitle string) error {
	return DB.Where("goods_title", goodsTitle).Limit(1).Find(&g).Error
}
